package com.huawei.appgallery.forum.message.fragment;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.text.TextUtils;
import androidx.annotation.NonNull;
import com.huawei.appgallery.forum.base.card.bean.Section;
import com.huawei.appgallery.forum.base.card.bean.User;
import com.huawei.appgallery.forum.base.ui.JGWTabFragment;
import com.huawei.appgallery.forum.message.bean.ForumRemindFollowCardBean;
import com.huawei.appgallery.forum.message.bean.ForumRemindGameMsgCardBean;
import com.huawei.appgallery.forum.user.api.IUserFollow;
import com.huawei.appgallery.foundation.ui.framework.cardframe.bean.BaseDetailResponse;
import com.huawei.appgallery.foundation.ui.framework.cardkit.bean.CardBean;
import com.huawei.hmf.annotation.FragmentDefine;
import com.huawei.secure.android.common.intent.SafeIntent;
import o.bqv;
import o.bqx;
import o.bri;
import o.bsl;
import o.bsv;
import o.bvj.c;
import o.bvj.j;
import o.bwm;
import o.bwz;
import o.chz;
import o.cia;
import o.fho;
import o.ll;

@FragmentDefine(alias = "message.detail", protocol = IMessageDetailFrgProtocol.class)
public class MessageDetailFragment extends JGWTabFragment {
    private IUserFollow ʻˊ;
    private String ʻˋ;
    private String ʼˋ;
    private b ꜝ;
    private e ﹳॱ;
    private int ﾞ;

    final class b extends BroadcastReceiver {
        final /* synthetic */ MessageDetailFragment ˊ;

        private b(MessageDetailFragment messageDetailFragment) {
            this.ˊ = messageDetailFragment;
        }

        public void onReceive(Context context, Intent intent) {
            Section section = (Section) new SafeIntent(intent).getSerializableExtra("section");
            if (section != null) {
                this.ˊ.ˏ(section);
            }
        }
    }

    final class e extends BroadcastReceiver {
        final /* synthetic */ MessageDetailFragment ˏ;

        private e(MessageDetailFragment messageDetailFragment) {
            this.ˏ = messageDetailFragment;
        }

        public void onReceive(Context context, Intent intent) {
            Intent safeIntent = new SafeIntent(intent);
            Object ˎ = this.ˏ.ʻˊ.ˎ(safeIntent);
            int ॱ = this.ˏ.ʻˊ.ॱ(safeIntent);
            if (!TextUtils.isEmpty(ˎ)) {
                this.ˏ.ˊ((String) ˎ, ॱ);
            }
        }
    }

    public void ˏ(Bundle bundle) {
        if (bundle == null) {
            ॱʾ();
        } else {
            this.ﾞ = bundle.getInt("key_message_detail_type");
            this.ʼˋ = bundle.getString("key_message_uri");
            this.ʻˋ = bundle.getString("key_message_domain_id");
        }
        bqv ॱ = bsv.ॱ(this.ʻˋ);
        ॱˉ();
        this.ʼ = new bsl(this, null, this.ʼˋ, ॱ);
        this.ʻˊ = (IUserFollow) fho.ˏ().ˋ("User").ॱ(IUserFollow.class);
        this.ﹳॱ = new e();
        this.ꜝ = new b();
        super.ˏ(bundle);
    }

    private void ॱʾ() {
        IMessageDetailFrgProtocol iMessageDetailFrgProtocol = (IMessageDetailFrgProtocol) this.ﹳ.ॱ();
        this.ﾞ = iMessageDetailFrgProtocol.getDetailType();
        this.ʼˋ = iMessageDetailFrgProtocol.getUri();
        this.ʻˋ = iMessageDetailFrgProtocol.getDomainId();
    }

    public void ˋ(@NonNull Bundle bundle) {
        bundle.putInt("key_message_detail_type", this.ﾞ);
        bundle.putString("key_message_uri", this.ʼˋ);
        bundle.putString("key_message_domain_id", this.ʻˋ);
        super.ˋ(bundle);
    }

    private void ॱˉ() {
        switch (this.ﾞ) {
            case 1:
                ʻ(c.ˊ);
                ʼ(j.ˎˏ);
                return;
            case 2:
                ʻ(c.ॱॱ);
                ʼ(j.ˍ);
                return;
            case 3:
                ʻ(c.ॱ);
                ʼ(j.ॱˎ);
                return;
            case 4:
                ʻ(c.ˋॱ);
                ʼ(j.ˋˊ);
                return;
            case 5:
                ʻ(c.ʻ);
                ʼ(j.ʽॱ);
                return;
            case 6:
                ʻ(c.ˏ);
                ʼ(j.ˈ);
                return;
            case 7:
                ʻ(c.ˋ);
                ʼ(j.ˏˏ);
                return;
            default:
                return;
        }
    }

    public cia ˊ(Context context) {
        return new bwm(context);
    }

    public void ˏ(bri o_bri, BaseDetailResponse baseDetailResponse) {
        super.ˏ(o_bri, baseDetailResponse);
        bqx.ˏ("MessageDetailFragment", "--------------handleResFailed-----------");
    }

    private void ˊ(String str, int i) {
        bqx.ˊ("MessageDetailFragment", "refreshFollowStatus: " + i + "uid is null?" + TextUtils.isEmpty(str));
        Object obj = null;
        for (chz ˏ : this.י.ʻॱ()) {
            for (CardBean cardBean : ˏ.ˏ()) {
                if (cardBean instanceof ForumRemindFollowCardBean) {
                    User ˊ = ((ForumRemindFollowCardBean) cardBean).ˊ();
                    if (!(ˊ == null || !str.equals(ˊ.ॱˋ()) || i == ˊ.ʻॱ())) {
                        ˊ.ˎ(i);
                        obj = 1;
                    }
                }
            }
        }
        if (obj != null) {
            bqx.ˊ("MessageDetailFragment", "provider.onDataChanged#");
            this.י.ˋॱ();
        }
    }

    private void ˏ(Section section) {
        bqx.ˊ("MessageDetailFragment", "refreshFollowSectionStatus sectionId : " + section.ˊ() + " follow status" + section.ᐝ());
        Object obj = null;
        for (chz ˏ : this.י.ʻॱ()) {
            for (CardBean cardBean : ˏ.ˏ()) {
                if (cardBean instanceof ForumRemindGameMsgCardBean) {
                    Section ͺ = ((ForumRemindGameMsgCardBean) cardBean).ͺ();
                    if (!(ͺ == null || ͺ.ˊ() != section.ˊ() || section.ᐝ() == ͺ.ᐝ())) {
                        ͺ.ˊ(section.ᐝ());
                        obj = 1;
                    }
                }
            }
        }
        if (obj != null) {
            bqx.ˊ("MessageDetailFragment", "refreshFollowSectionStatus provider.onDataChanged#");
            this.י.ˋॱ();
        }
    }

    public void ˋʼ() {
        super.ˋʼ();
        if (ॱˊ() != null) {
            ll.ˏ(ॱˊ()).ˋ(this.ﹳॱ);
            ll.ˏ(ॱˊ()).ˋ(this.ꜝ);
        }
    }

    public void ˌॱ() {
        super.ˌॱ();
        if (ॱˊ() != null) {
            IntentFilter ˎ = this.ʻˊ.ˎ();
            if (ˎ != null) {
                ll.ˏ(ॱˊ()).ˏ(this.ﹳॱ, ˎ);
            }
            ll.ˏ(ॱˊ()).ˏ(this.ꜝ, new IntentFilter(bwz.ˎ));
        }
    }
}
